import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:loxen/api/http_server/dictionaries.dart';
import 'package:loxen/api/http_server/material_order.dart';
import 'package:loxen/api/http_server/send_email.dart';
import 'package:loxen/api/http_server/statistics.dart';
import 'package:loxen/dialog/toast.dart';
import 'package:loxen/mode/material/material_info.dart';
import 'package:loxen/routes/routes.dart';
import 'package:loxen/utils/config.dart';
import 'package:loxen/utils/format_time.dart';
import 'package:loxen/utils/image_url.dart';
import 'package:loxen/utils/string_res.dart';
import 'package:loxen/view/material/material_order_receive/material_order_list_widget.dart';
import 'package:loxen/viewmode/base_view_model.dart';
import 'package:loxen/viewmode/login_view_model.dart';
import 'package:loxen/viewmode/material_detail_viewmodel.dart';
import 'package:loxen/widget/fail_widget.dart';
import 'package:loxen/widget/loading_widget.dart';
import 'package:loxen/widget/my_subassembly.dart';
import 'package:provider/provider.dart';

class MaterialDetailWidget extends StatelessWidget
    with SendEmailMixin, StatisticsMixin, MaterialOrderMixin {
  final ScrollController scrollController = ScrollController();
  final ValueNotifier<int> orderNum = ValueNotifier(0);

  final int id;
  final ValueNotifier<int> _titleOpacity = ValueNotifier(0);
  final double _presetOffset = 50;

  MaterialDetailWidget({Key key, this.id}) : super(key: key) {
    scrollController.addListener(() {
      double offset = scrollController.offset;
      _titleOpacity.value = offset > _presetOffset ? 255 : offset * 255 ~/ _presetOffset;
    });
    statisticeMaterialProduct(id.toString());
    shiocarNum().listen((event) {
      orderNum.value = event;
    });
  }

  @override
  Widget build(BuildContext context) {
    bool isLogin = Provider.of<LoginViewModel>(context, listen: false).isLogin();
    return ChangeNotifierProvider<MaterialDetailViewModel>(
      create: (_) {
        MaterialDetailViewModel model = MaterialDetailViewModel();
        model.loadData(id);
        return model;
      },
      child: Scaffold(
        extendBodyBehindAppBar: true,
        appBar: PreferredSize(
          preferredSize: Size(double.infinity, 95.h),
          child: ValueListenableProvider.value(
            value: _titleOpacity,
            builder: (context, _) {
              return Container(
                color: Theme.of(context).primaryColor.withAlpha(context.watch<int>()),
                child: SafeArea(
                  child: Row(
                    children: <Widget>[
                      MySubassembly.getBackIcon(context),
                      Expanded(
                          child: Selector<MaterialDetailViewModel, BaseState>(
                              builder: (context, state, __) {
                                if (state == BaseState.CONTENT) {
                                  return Center(
                                    child: Text(
                                      Provider.of<MaterialDetailViewModel>(context)
                                          .infoBean
                                          .data
                                          .results
                                          .name,
                                      style: TextStyle(
                                          fontSize: 31.sp,
                                          color: Theme.of(context).textTheme.subtitle1.color),
                                    ),
                                  );
                                }
                                return Text('');
                              },
                              selector: (_, model) => model.mState)),
                      MySubassembly.getSearchIcon(
                        () {
                          // Navigator.of(context).pushNamed(Routes.material_order_receive);
                          Navigator.of(context)
                              .push(MaterialPageRoute(builder: (_) => MaterialOrderListWidget()))
                              .then((value) => shiocarNum().listen((event) {
                                    orderNum.value = event;
                                  }));
                        },
                        text: Stack(
                          children: [
                            Align(
                              alignment: Alignment.center,
                              child: Image.asset(
                                'images/order.png',
                                width: 40.w,
                                height: 40.w,
                              ),
                            ),
                            Align(
                              alignment: Alignment.topRight,
                              child: ValueListenableProvider.value(
                                value: orderNum,
                                builder: (context, _) {
                                  var num = context.watch<int>();
                                  Widget text;
                                  if (num == 0) {
                                    return Constants.empty;
                                  } else {
                                    String str;
                                    if (num > 9) {
                                      str = '9+';
                                    } else {
                                      str = num.toString();
                                    }
                                    text = Text(
                                      str,
                                      style: TextStyle(
                                        fontSize: 16.sp,
                                        color: Colors.white,
                                      ),
                                    );
                                  }
                                  return Container(
                                    alignment: Alignment.center,
                                    child: text,
                                    margin: EdgeInsets.only(top: 15.h, right: 15.h),
                                    width: 25.w,
                                    height: 25.w,
                                    decoration: BoxDecoration(
                                      borderRadius: BorderRadius.circular(20.w),
                                      color: Colors.red,
                                    ),
                                  );
                                },
                              ),
                            )
                          ],
                        ),
                      )
                    ],
                  ),
                ),
              );
            },
          ),
        ),
        body: Selector<MaterialDetailViewModel, BaseState>(
            builder: (context, state, __) {
              if (state == BaseState.CONTENT) {
                var info = Provider.of<MaterialDetailViewModel>(context, listen: false)
                    .infoBean
                    .data
                    .results;
                return MediaQuery.removePadding(
                  context: context,
                  removeTop: true,
                  child: Container(
                    color: Theme.of(context).backgroundColor,
                    child: Stack(
                      children: <Widget>[
                        ListView(
                          controller: scrollController,
                          physics: ClampingScrollPhysics(),
                          children: <Widget>[
                            CachedNetworkImage(
                              imageUrl: ImageUrlUtil.getClean(info.cover),
                              placeholder: (_, __) => Constants.loadingIcon(),
                              fit: BoxFit.cover,
                            ), //板材图
                            Padding(
                              padding: EdgeInsets.only(left: 37.w, top: 78.h),
                              child: Row(
                                crossAxisAlignment: CrossAxisAlignment.end,
                                children: <Widget>[
                                  Expanded(
                                      child: Text(
                                    info.name,
                                    style: TextStyle(
                                        fontSize: 32.sp,
                                        fontWeight: FontWeight.bold,
                                        color: Theme.of(context).textTheme.subtitle2.color),
                                  )),
                                  _tag('images/eye.png', info.view_num, width: 32.w, height: 24.w),
                                  Padding(
                                    padding: EdgeInsets.only(left: 30.w),
                                    child: Selector<MaterialDetailViewModel, bool>(
                                        builder: (_, data, __) {
                                      String img;
                                      if (data) {
                                        img = "images/like_active.png";
                                      } else {
                                        img = "images/like.png";
                                      }
                                      return _tag(img, info.like_num, width: 30.w, height: 30.w);
                                    }, selector: (_, model) {
                                      return model.infoBean.data.results.is_like == 1;
                                    }),
                                  ),
                                  Padding(
                                    padding: EdgeInsets.only(left: 30.w, right: 30.w),
                                    child: Selector<MaterialDetailViewModel, bool>(
                                        builder: (_, data, __) {
                                      String img;
                                      if (data) {
                                        img = "images/collected.png";
                                      } else {
                                        img = "images/collect.png";
                                      }
                                      return _tag(img, info.collect_num, width: 30.w, height: 30.w);
                                    }, selector: (_, model) {
                                      return model.infoBean.data.results.is_collect == 1;
                                    }),
                                  ),
                                ],
                              ),
                            ), //标题
                            Padding(
                              padding: EdgeInsets.only(left: 37.w, top: 38.h),
                              child: Text(
                                "${StringResources.pin_pai}:${info?.brand?.name ?? ''}",
                                style: TextStyle(fontSize: 24.sp, color: Color(0xFF82868E)),
                              ),
                            ),
                            Padding(
                              padding: EdgeInsets.only(left: 37.w, top: 10.h),
                              child: Text(
                                "${StringResources.xing_hao}:${info.code}",
                                style: TextStyle(fontSize: 24.sp, color: Color(0xFF82868E)),
                              ),
                            ), //型号
                            Builder(builder: (context) {
                              if (info.related != null && info.related.length > 0) {
                                return Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  mainAxisSize: MainAxisSize.min,
                                  children: <Widget>[
                                    Padding(
                                      padding: EdgeInsets.only(left: 37.w, top: 80.h),
                                      child: Text(
                                        StringResources.qi_ta_yan_se,
                                        style: TextStyle(fontSize: 24.sp, color: Color(0xFF82868E)),
                                      ),
                                    ), //其他颜色
                                    Padding(
                                      padding: EdgeInsets.only(left: 37.w, top: 38.h),
                                      child: Container(
                                        width: double.infinity,
                                        height: 126.h,
                                        child: info.related != null && info.related.length > 0
                                            ? GridView.count(
                                                mainAxisSpacing: 10.w,
                                                crossAxisCount: 1,
                                                scrollDirection: Axis.horizontal,
                                                children: _itemImage(context, info),
                                              )
                                            : Constants.empty,
                                      ),
                                    ), //素材列表
                                  ],
                                );
                              } else {
                                return Constants.empty;
                              }
                            }),
                            Padding(
                              padding: EdgeInsets.only(left: 37.w, top: 80.h),
                              child: Text(
                                StringResources.su_cai_gu_shi,
                                style: TextStyle(
                                    fontSize: 32.sp,
                                    fontWeight: FontWeight.bold,
                                    color: Theme.of(context).textTheme.subtitle2.color),
                              ),
                            ), //素材故事
                            Padding(
                                padding: EdgeInsets.only(left: 37.w, top: 40.h, right: 37.w),
                                child: _getGuShi(context, info)),
                            Container(
                              margin: EdgeInsets.only(top: 40.h),
                              height: 10.h,
                              width: double.infinity,
                              color: Color(0xFFF1F1F1),
                            ),
                            Container(
                              padding: EdgeInsets.only(left: 37.w, top: 80.h),
                              child: Text(
                                '应用场景',
                                style: TextStyle(
                                    fontSize: 32.sp,
                                    fontWeight: FontWeight.bold,
                                    color: Theme.of(context).textTheme.subtitle2.color),
                              ),
                            ),
                            Container(
                              margin: EdgeInsets.only(left: 37.w, top: 40.h, right: 37.w),
                              child: info.image != null && info.image.trim() != ''
                                  ? CachedNetworkImage(
                                      height: 450.h,
                                      width: double.infinity,
                                      imageUrl: ImageUrlUtil.getClean(info.image),
                                      placeholder: (_, __) => Constants.loadingIcon(),
                                      fit: BoxFit.cover,
                                    )
                                  : Text(
                                      StringResources.mei_you_chang_jing,
                                      style: TextStyle(
                                          fontSize: 24.sp,
                                          color: Theme.of(context).textTheme.subtitle2.color),
                                    ),
                            ),
                            Container(
                              margin: EdgeInsets.only(top: 40.h),
                              height: 10.h,
                              width: double.infinity,
                              color: Color(0xFFF1F1F1),
                            ),
                            Container(
                              padding: EdgeInsets.only(left: 37.w, top: 80.h),
                              child: Text(
                                '关联灵感',
                                style: TextStyle(
                                    fontSize: 32.sp,
                                    fontWeight: FontWeight.bold,
                                    color: Theme.of(context).textTheme.subtitle2.color),
                              ),
                            ),
                            Padding(
                              padding: EdgeInsets.only(top: 40.h, left: 35.w, right: 35.w),
                              child: _getInspiration(context),
                            )
                          ],
                        ),
                        Positioned(
                            bottom: 50.h,
                            child: Row(
                              mainAxisSize: MainAxisSize.max,
                              children: <Widget>[
                                _customMainButton(
                                    test: Text(
                                      StringResources.shi_yang,
                                      maxLines: 1,
                                      style: TextStyle(
                                          fontSize: 22.sp,
                                          color: Theme.of(context).textTheme.subtitle1.color),
                                    ),
                                    isSelected: true,
                                    onPressed: () {
                                      if (isLogin) {
                                        Navigator.of(context).pushNamed(Routes.login_page);
                                        return;
                                      }
                                      shopcar(info.id.toString()).listen((event) {
                                        if (event['code'] == 2000) {
                                          Toast.show('添加样单成功', context);
                                          orderNum.value += 1;
                                        } else {
                                          Toast.show(event['data']['msg'], context);
                                        }
                                      }, onError: (error, stack) {
                                        Toast.show('网络异常', context);
                                      });
                                    }),
                                _customMainButton(
                                    test: Text(
                                      StringResources.tie_tu,
                                      maxLines: 1,
                                      style: TextStyle(
                                          fontSize: 22.sp,
                                          color: Theme.of(context).textTheme.subtitle1.color),
                                    ),
                                    isSelected: true,
                                    onPressed: () {
                                      if (isLogin) {
                                        Navigator.of(context).pushNamed(Routes.login_page);
                                      } else {
                                        showDialog(
                                            context: context,
                                            builder: (context) {
                                              String email =
                                                  Provider.of<LoginViewModel>(context).edit?.email;
                                              TextEditingController controller =
                                                  TextEditingController();
                                              if (email != null && email.trim().length > 0) {
                                                controller.text = email;
                                              }
                                              return AlertDialog(
                                                content: Column(
                                                  mainAxisSize: MainAxisSize.min,
                                                  children: <Widget>[
                                                    Container(
                                                      margin: EdgeInsets.only(bottom: 30.h),
                                                      alignment: Alignment.topLeft,
                                                      child: Text(
                                                        StringResources.you_xiang_fa_song,
                                                        style: TextStyle(
                                                          fontSize: 32.sp,
                                                          fontWeight: FontWeight.bold,
                                                          color: Theme.of(context)
                                                              .textTheme
                                                              .subtitle2
                                                              .color,
                                                        ),
                                                      ),
                                                    ),
                                                    Container(
                                                      padding: EdgeInsets.only(
                                                        top: 6.h,
                                                        bottom: 6.h,
                                                      ),
                                                      decoration: BoxDecoration(
                                                          border:
                                                              Border.all(color: Color(0xFF999999))),
                                                      child: TextField(
                                                        controller: controller,
                                                        style: TextStyle(
                                                          fontSize: 28.sp,
                                                          color: Theme.of(context)
                                                              .textTheme
                                                              .subtitle2
                                                              .color,
                                                        ),
                                                        decoration: InputDecoration(
                                                          hintText: "请输入邮箱地址",
                                                          border: InputBorder.none,
                                                          isDense: true,
                                                        ),
                                                      ),
                                                    ),
                                                  ],
                                                ),
                                                actions: <Widget>[
                                                  FlatButton(
                                                    child: Text(StringResources.qu_xiao),
                                                    onPressed: () => Navigator.of(context).pop(),
                                                  ),
                                                  FlatButton(
                                                    child: Text(StringResources.que_ding),
                                                    onPressed: () {
                                                      sendEmail(controller.text, id.toString(),
                                                          onSuccess: () {
                                                        Toast.show("发送成功", context);
                                                        Navigator.of(context).pop();
                                                      }, onError: (msg) {
                                                        Toast.show(msg, context);
                                                      });
                                                    },
                                                  ),
                                                ],
                                              );
                                            });
                                      }
                                    }),
                                Padding(
                                  padding: EdgeInsets.only(left: 200.w),
                                  child: Builder(builder: (context) {
                                    bool collection = context.select<MaterialDetailViewModel, bool>(
                                        (value) => value.infoBean.data.results.is_collect == 1);
                                    return _customMainButton(
                                        iconPath: 'images/collation_false.png',
                                        selectedIconPath: 'images/collation_true.png',
                                        isSelected: collection,
                                        onPressed: () async {
                                          if (isLogin) {
                                            Navigator.of(context).pushNamed(Routes.login_page);
                                            return;
                                          }
                                          if (collection) {
                                            bool data = await showDialog(
                                                context: context,
                                                builder: (context) => AlertDialog(
                                                      title: Text('提示'),
                                                      content: Text(
                                                        '是否取消收藏？',
                                                        style: TextStyle(color: Colors.black),
                                                      ),
                                                      actions: <Widget>[
                                                        FlatButton(
                                                          child: Text(StringResources.qu_xiao),
                                                          onPressed: () =>
                                                              Navigator.of(context).pop(),
                                                        ),
                                                        FlatButton(
                                                          child: Text(StringResources.que_ding),
                                                          onPressed: () {
                                                            Navigator.of(context).pop(true);
                                                          },
                                                        ),
                                                      ],
                                                    ));
                                            if (data != null && data) {
                                              context
                                                  .read<MaterialDetailViewModel>()
                                                  .unThisCollection(
                                                      onShow: (msg) => Toast.show(msg, context));
                                            }
                                          } else {
                                            Navigator.of(context).pushNamed(Routes.master_file_add,
                                                arguments: {
                                                  'type': FileType.MATERIAL,
                                                  'id': id.toString()
                                                }).then((value) {
                                              if (value) {
                                                context
                                                    .read<MaterialDetailViewModel>()
                                                    .thisCollection();
                                              }
                                            });
                                          }
                                        });
                                  }),
                                ),
                                Selector<MaterialDetailViewModel, int>(
                                    builder: (context, data, __) {
                                      return _customMainButton(
                                          iconPath: 'images/like_false.png',
                                          selectedIconPath: 'images/like_true.png',
                                          isSelected: data == 1,
                                          onPressed: () {
                                            if (isLogin) {
                                              Navigator.of(context).pushNamed(Routes.login_page);
                                            } else {
                                              if (data == 0) {
                                                Provider.of<MaterialDetailViewModel>(context,
                                                        listen: false)
                                                    .likeThis();
                                              } else {
                                                Provider.of<MaterialDetailViewModel>(context,
                                                        listen: false)
                                                    .unlikeThis();
                                              }
                                            }
                                          });
                                    },
                                    selector: (_, model) => model.infoBean.data.results.is_like)
                              ],
                            )),
                      ],
                    ),
                  ),
                );
              }
              if (state == BaseState.FAIL) {
                return FailWidget(
                  onClick: () {
                    Provider.of<MaterialDetailViewModel>(context, listen: false).loadData(id);
                  },
                );
              }
              if (state == BaseState.LOADING) {
                return LoadingWidget();
              }
              return Text('');
            },
            selector: (_, model) => model.mState),
      ),
    );
  }

  Widget _getInspiration(BuildContext context) {
    List list = Provider.of<MaterialDetailViewModel>(context).infoBean.data.results.article;
    if (list != null && list.length > 0) {
      List<Widget> widgets = list.map((entity) {
        return Column(
          children: <Widget>[
            Container(
              height: 450.h,
              child: GestureDetector(
                onTap: () {
                  Navigator.of(context)
                      .pushNamed(Routes.inspiration_detail, arguments: entity)
                      .then((value) {
                    context.read<MaterialDetailViewModel>().changeEntity();
                  });
                },
                child: CachedNetworkImage(
                  imageUrl: ImageUrlUtil.getClean(entity.cover),
                  width: double.infinity,
                  height: 450.h,
                  placeholder: (_, __) => Constants.loadingIcon(),
                  fit: BoxFit.cover,
                ),
              ),
            ),
            Padding(
              padding: EdgeInsets.only(top: 15.h),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Expanded(
                      child: Text(
                    entity.title,
                    maxLines: 1,
                    overflow: TextOverflow.ellipsis,
                    style: TextStyle(
                      color: Colors.black,
                      fontSize: 27.sp,
                      fontWeight: FontWeight.w500,
                    ),
                  )),
                  Text(
                    FormatTime.readTimestamp(entity.add_time),
                    style: TextStyle(
                        color: Color(0xFF999999), fontSize: 22.sp, fontWeight: FontWeight.w500),
                  )
                ],
              ),
            ), //标题  时间
            Container(
              margin: EdgeInsets.only(bottom: 30.h),
              child: Row(
                children: <Widget>[
                  Expanded(
                    child: Row(
                      children: <Widget>[
                        Container(
                            width: 52.w,
                            height: 52.w,
                            decoration: BoxDecoration(
                                shape: BoxShape.circle,
                                image: DecorationImage(
                                    image: NetworkImage(
                                      entity?.user?.portrait,
                                    ),
                                    fit: BoxFit.cover))),
                        Padding(
                          padding: EdgeInsets.only(left: 15.w),
                          child: Text(
                            entity?.user?.nickname,
                            style: TextStyle(color: Color(0xFF82868E), fontSize: 21.sp),
                          ),
                        )
                      ],
                    ),
                  ),
                  Builder(builder: (context) {
                    bool isLogin = Provider.of<LoginViewModel>(context).isLogin();
                    bool isLike = context
                        .select<MaterialDetailViewModel, bool>((value) => entity.is_like == 0);
                    return Padding(
                      padding: EdgeInsets.only(right: 20.w),
                      child: SizedBox(
                        width: 72.w,
                        child: FlatButton(
                          padding: EdgeInsets.all(1.w),
                          onPressed: () {
                            if (isLogin) {
                              Navigator.of(context).pushNamed(Routes.login_page);
                            } else {
                              if (isLike) {
                                context.read<MaterialDetailViewModel>().likeInspiration(entity);
                              } else {
                                context.read<MaterialDetailViewModel>().unLikeInspiration(entity);
                              }
                            }
                          },
                          child: Stack(
                            alignment: Alignment.centerLeft,
                            children: <Widget>[
                              Image.asset(
                                isLike ? "images/like.png" : "images/like_active.png",
                                width: 30.w,
                                height: 30.w,
                                fit: BoxFit.cover,
                              ),
                              Padding(
                                padding: EdgeInsets.only(
                                  left: 37.w,
                                  top: 4.h,
                                ),
                                child: Text(
                                  '${entity.like_num}',
                                  style: TextStyle(
                                      fontSize: 22.sp,
                                      color: isLike ? Color(0xFF999999) : Color(0xFF0CABCB)),
                                ),
                              )
                            ],
                          ),
                        ),
                      ),
                    );
                  }),
                  Padding(
                    padding: EdgeInsets.only(right: 20.w),
                    child: SizedBox(
                      width: 72.w,
                      child: FlatButton(
                        padding: EdgeInsets.all(1.w),
                        onPressed: () {
                          Navigator.of(context)
                              .pushNamed(Routes.inspiration_detail, arguments: entity)
                              .then((value) {
                            context.read<MaterialDetailViewModel>().changeEntity();
                          });
                        },
                        child: Stack(
                          alignment: Alignment.centerLeft,
                          children: <Widget>[
                            Image.asset(
                              'images/comment.png',
                              width: 30.w,
                              height: 30.w,
                              fit: BoxFit.cover,
                            ),
                            Padding(
                              padding: EdgeInsets.only(
                                left: 37.w,
                                top: 4.h,
                              ),
                              child: Text(
                                '${entity.comment_num}',
                                style: TextStyle(fontSize: 22.sp, color: Color(0xFF999999)),
                              ),
                            )
                          ],
                        ),
                      ),
                    ),
                  ),
                  Builder(builder: (context) {
                    bool collection = context
                        .select<MaterialDetailViewModel, bool>((value) => entity.is_collect == 0);
                    return SizedBox(
                      width: 72.w,
                      child: FlatButton(
                        padding: EdgeInsets.all(1.w),
                        onPressed: () {
                          if (context.read<LoginViewModel>().isLogin()) {
                            Navigator.of(context).pushNamed(Routes.login_page);
                            return;
                          }
                          if (collection) {
                            Navigator.of(context).pushNamed(Routes.master_file_add, arguments: {
                              'type': FileType.INSPIRATION,
                              'id': entity.id.toString()
                            }).then((value) {
                              if (value) {
                                entity.is_collect = 1;
                                entity.collect_num += 1;
                                context.read<MaterialDetailViewModel>().changeEntity();
                              }
                            });
                          } else {
                            context.read<MaterialDetailViewModel>().unCollection(entity);
                          }
                        },
                        child: Stack(
                          alignment: Alignment.centerLeft,
                          children: <Widget>[
                            Image.asset(
                              collection ? "images/collect.png" : "images/collected.png",
                              width: 30.w,
                              height: 30.w,
                              fit: BoxFit.cover,
                            ),
                            Padding(
                              padding: EdgeInsets.only(
                                left: 37.w,
                                top: 4.h,
                              ),
                              child: Text(
                                '${entity.collect_num}',
                                style: TextStyle(
                                    fontSize: 22.sp,
                                    color: collection ? Color(0xFF999999) : Color(0xFF0CABCB)),
                              ),
                            )
                          ],
                        ),
                      ),
                    );
                  }),
                ],
              ),
            )
          ],
        );
      }).toList();
      return Column(
        children: widgets,
      );
    } else {
      return Container(
        height: 100.h,
        child: Text(
          StringResources.mei_you_ling_gan,
          style: TextStyle(fontSize: 24.sp, color: Theme.of(context).textTheme.subtitle2.color),
        ),
      );
    }
  }

  Widget _tag(String img, int num, {double width = 15, double height = 15}) {
    return Row(
      mainAxisSize: MainAxisSize.min,
      children: <Widget>[
        Image.asset(
          img,
          width: width,
          height: height,
        ),
        Padding(
          padding: EdgeInsets.only(left: 5.w),
          child: Text(
            "$num",
            style: TextStyle(fontSize: 22.sp, color: Color(0xFF999999)),
          ),
        )
      ],
    );
  }

  List<Widget> _itemImage(BuildContext context, MaterialInfo info) {
    return info.related
        .map((entity) => InkWell(
              onTap: () {
                Navigator.of(context).pushNamed(Routes.material_detail, arguments: entity.id);
              },
              child: Stack(
                alignment: Alignment.center,
                children: <Widget>[
                  ClipRRect(
                      borderRadius: BorderRadius.circular(10.w),
                      child: CachedNetworkImage(
                        imageUrl: ImageUrlUtil.getClean(entity.cover),
                        placeholder: (_, __) => Constants.loadingIcon(),
                        fit: BoxFit.cover,
                        width: double.infinity,
                        height: double.infinity,
                      )),
                  Align(
                    alignment: Alignment.bottomCenter,
                    child: Container(
                      height: 32.h,
                      alignment: Alignment.center,
                      decoration: BoxDecoration(
                        color: Colors.black26,
                        borderRadius: BorderRadius.only(
                          bottomLeft: Radius.circular(10.w),
                          bottomRight: Radius.circular(10.w),
                        ),
                      ),
                      child: Text(
                        entity.code,
                        style: TextStyle(
                            fontSize: 19.sp,
                            color: Theme.of(context).textTheme.subtitle1.color,
                            fontWeight: FontWeight.w500),
                      ),
                    ),
                  )
                ],
              ),
            ))
        .toList();
  }

  Widget _getGuShi(BuildContext context, MaterialInfo info) {
    String content;
    if (info.story != null && info.story.trim() != '') {
      content = info.story;
    } else {
      content = StringResources.mei_you_gu_shi;
    }
    return Text(
      content,
      style: TextStyle(fontSize: 24.sp, color: Theme.of(context).textTheme.subtitle2.color),
    );
  }

  Widget _customButton({iconPath, selectedIconPath, isSelected = false, onPressed}) {
    return SizedBox(
      child: InkWell(
        onTap: onPressed,
        child: Image.asset(
          isSelected ? selectedIconPath : iconPath,
          width: 108.w,
          height: 109.w,
        ),
      ),
    );
  }

  Widget _customMainButton(
      {iconPath, test, iconWidth = 18.5, selectedIconPath, isSelected = false, onPressed}) {
    return GestureDetector(
      onTap: onPressed,
      child: Container(
        margin: const EdgeInsets.only(left: 16.0),
        alignment: Alignment.center,
        width: 100.w,
        height: 100.w,
        decoration: BoxDecoration(
          image: DecorationImage(
              image: AssetImage(
                  (isSelected ? selectedIconPath : iconPath) ?? 'images/bg_icon_text.png')),
          shape: BoxShape.circle,
        ),
        child: test ?? Constants.empty,
      ),
    );
  }
}
